home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / FLTK-1.0.6 / src / Fl_Choice.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1999-03-16  |  2.7 KB  |  95 lines

  1. //
  2. // "$Id: Fl_Choice.cxx,v 1.10.2.2 1999/03/16 08:51:02 bill Exp $"
  3. //
  4. // Choice widget for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-1999 by Bill Spitzak and others.
  7. //
  8. // This library is free software; you can redistribute it and/or
  9. // modify it under the terms of the GNU Library General Public
  10. // License as published by the Free Software Foundation; either
  11. // version 2 of the License, or (at your option) any later version.
  12. //
  13. // This library is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16. // Library General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Library General Public
  19. // License along with this library; if not, write to the Free Software
  20. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  21. // USA.
  22. //
  23. // Please report all bugs and problems to "fltk-bugs@easysw.com".
  24. //
  25.  
  26. #include <FL/Fl.H>
  27. #include <FL/Fl_Choice.H>
  28. #include <FL/fl_draw.H>
  29.  
  30. // Emulates the Forms choice widget.  This is almost exactly the same
  31. // as an Fl_Menu_Button.  The only difference is the appearance of the
  32. // button: it draws the text of the current pick and a down-arrow.
  33.  
  34. extern char fl_draw_shortcut;
  35.  
  36. void Fl_Choice::draw() {
  37.   draw_box();
  38.   if (box() == FL_FLAT_BOX) return; // for XForms compatability
  39.   int H = labelsize()/2+1;
  40.   draw_box(FL_THIN_UP_BOX,x()+w()-3*H,y()+(h()-H)/2,2*H,H,color());
  41.   if (mvalue()) {
  42.     Fl_Menu_Item m = *mvalue();
  43.     if (active_r()) m.activate(); else m.deactivate();
  44.     int BW = Fl::box_dx(box());
  45.     fl_clip(x(), y(), w()-3*H, h());
  46.     fl_draw_shortcut = 2; // hack value to make '&' disappear
  47.     m.draw(x()+BW, y(), w()-2*BW-3*H, h(), this);
  48.     fl_draw_shortcut = 0;
  49.     fl_pop_clip();
  50.   }
  51.   draw_label();
  52. }
  53.  
  54. Fl_Choice::Fl_Choice(int x,int y,int w,int h, const char *l)
  55. : Fl_Menu_(x,y,w,h,l) {
  56.   align(FL_ALIGN_LEFT);
  57.   when(FL_WHEN_RELEASE);
  58.   textfont(FL_HELVETICA);
  59.   down_box(FL_NO_BOX);
  60. }
  61.  
  62. int Fl_Choice::value(int v) {
  63.   if (!Fl_Menu_::value(v)) return 0;
  64.   redraw();
  65.   return 1;
  66. }
  67.  
  68. int Fl_Choice::handle(int e) {
  69.   if (!menu() || !menu()->text) return 0;
  70.   const Fl_Menu_Item* v;
  71.   switch (e) {
  72.   case FL_PUSH:
  73.     Fl::event_is_click(0);
  74.   J1:
  75.     v = menu()->pulldown(x(), y(), w(), h(), mvalue(), this);
  76.     if (!v || v->submenu()) return 1;
  77.     if (v != mvalue()) redraw();
  78.     picked(v);
  79.     return 1;
  80.   case FL_SHORTCUT:
  81.     if (Fl_Widget::test_shortcut()) goto J1;
  82.     v = menu()->test_shortcut();
  83.     if (!v) return 0;
  84.     if (v != mvalue()) redraw();
  85.     picked(v);
  86.     return 1;
  87.   default:
  88.     return 0;
  89.   }
  90. }
  91.  
  92. //
  93. // End of "$Id: Fl_Choice.cxx,v 1.10.2.2 1999/03/16 08:51:02 bill Exp $".
  94. //
  95.